package fun.yegang.web.controller;

import fun.yegang.utils.UserUtils;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class IndexController {

    @GetMapping(value = "test")
    public String test() {
        return UserUtils.getUserFromOauth2();
    }

    @GetMapping(value = "/")
    public String index() {
        return "Welcome ";
    }

    @GetMapping("/isLoggedIn")
    public String isLoggedIn() {
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();

        if (authentication != null && authentication.isAuthenticated()) {
            return "User is logged in";
        } else {
            return "User is not logged in";
        }
    }
}
